package com.joey.concurrency.example.threadPool;

import lombok.extern.slf4j.Slf4j;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Author hyy
 **/
@Slf4j
public class ThreadPoolExample4 {

    public static void main(String[] args) {
        //不乱序，就一个工作线程
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
//        scheduledExecutorService.schedule(new Runnable() {
//            @Override
//            public void run() {
//                log.warn("延迟执行...");
//            }
//        },3, TimeUnit.SECONDS);

//        scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
//            @Override
//            public void run() {
//                log.warn("延迟执行...");
//            }
//            //延迟8秒，循环周期3秒
//        },8,4,TimeUnit.SECONDS);
//        scheduledExecutorService.shutdown();

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                log.warn("延迟执行...");
            }
            //间隔5秒继续执行
        },new Date(),5 * 1000);

    }
}
